package oa.hleast.xswl.pojo.domain.pms;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import oa.hleast.common.base.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import oa.hleast.xswl.common.enums.MarketingFieldTypeEnum;
import oa.hleast.xswl.pojo.dto.pms.SkuDTO;

import java.util.Date;

/**
 * @author: 00209
 * @date: 2021-06-21 15:44:29
 * @description: 营销场管理表(PmsMarketingField)实体类
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("营销场管理表实体类")
public class PmsMarketingField extends BaseEntity {
    @TableId(type = IdType.AUTO)
    @ApiModelProperty("")
    private Long id;

    @ApiModelProperty("名称")
    private String name;

    @ApiModelProperty("主图")
    private String picUrl;

    @ApiModelProperty("营销价")
    private Long price;

    @ApiModelProperty("营销类型与订单类型值相对应 2限时购 3拼组团 4众筹")
    private Integer type;

    @ApiModelProperty("简介")
    private String intro;

    @ApiModelProperty("开始时间")
    private Date start;

    @ApiModelProperty("结束时间")
    private Date end;
    @ApiModelProperty("开始时间 timestamp 毫秒")
    public Long getStartTimestamp() {
        return start.getTime();
    }

    @ApiModelProperty("结束时间timestamp 毫秒")
    public Long getEndTimestamp() {
        return end.getTime();
    }

    @ApiModelProperty("当前参加人数")
    private Long curBuyNums;

    @ApiModelProperty("当前营销金额")
    private Long curBuyPrices;

    @ApiModelProperty("营销规则：根据类型表示不同的值， 限时购：无， 拼组团：人数， 众筹：金额")
    private Long ruleValue;

    @ApiModelProperty("商品skuId")
    private Long skuId;

    @ApiModelProperty("商品skuName")
    private String skuName;

    @ApiModelProperty("商品spuId")
    private Long spuId;

    @ApiModelProperty("营销场活动是否成功")
    public Boolean isSuccess() {
        Boolean b = true;
        MarketingFieldTypeEnum marketingFieldTypeEnum = MarketingFieldTypeEnum.getValue(type);
        switch (marketingFieldTypeEnum) {
            case GROUP: b = curBuyNums >= ruleValue; break;
            case CROWDFUNDING: b = curBuyPrices >= ruleValue; break;
        }
        return b;
    }

    @ApiModelProperty("商品sku信息")
    @TableField(exist = false)
    private SkuDTO skuDTO;
    @ApiModelProperty("商品spu信息")
    @TableField(exist = false)
    private PmsSpu pmsSpu;

    @ApiModelProperty("状态：0-下架 1-上架")
    private Integer status;

    @ApiModelProperty("显示顺序")
    private Integer sort;
    @TableLogic(value = "0", delval = "1")
    @ApiModelProperty("删除标识  (0未删除 1已删除)")
    private Integer deleted;


}
